import tensorflow as tf
from PyQt5.QtCore import QThread, pyqtSignal

# 导出模型的线程
class OutputModelThread(QThread):
    # 传递string类型的参数
    signal = pyqtSignal(str)

    def __init__(self):
        super(OutputModelThread, self).__init__()
        self.model = None

    def run(self):
        # 4. 保存模型
        self.model.save("models/new_model.h5")
        # 5. 转换为tflite模型
        h5_model = tf.keras.models.load_model("models/new_model.h5")
        converter = tf.lite.TFLiteConverter.from_keras_model(h5_model)
        tflite_model = converter.convert()
        open("models/new_model.tflite", "wb").write(tflite_model)

        self.signal.emit(str("保存模型完成"))
